package org.example.leetcpde;

import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class subsets {
    @Test
    void run() {
        int[] nums = {1, 2, 3};
        List<List<Integer>> subsets = subsets(nums);

        System.out.println(11);
    }


    public List<List<Integer>> subsets(int[] nums) {
        Arrays.sort(nums);
        List<List<Integer>> res = new ArrayList<>();
        dfs(new ArrayList<>(), res, 0, nums);
        return res;
    }

    void dfs(List<Integer> cur,
             List<List<Integer>> res,
             int start,
             int[] nums) {

        res.add(new ArrayList<>(cur));
        if (cur.size() == nums.length) {
            return;
        }

        for (int i = start; i < nums.length; i++) {
            cur.add(nums[i]);
            dfs(cur, res, i + 1, nums);
            cur.remove(cur.size() - 1);
        }
    }
}
